/**
*      author: Y_Yao
*      created: 2025-04-26 20:09:55
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 9e18;
const int INF = 0x3f3f3f3f;
const int N = 1e4 + 5;
int n;
string s;
string ans;
vector<int> a;

int cnt[11];

void solve()
{
    cin >> s;
    memset(cnt,0,sizeof cnt);
    ans = s;
    for(int i = 0;i < s.size();i++)
    {
        cnt[s[i] - '0']++;
    }

    for(int i = 1;i <= s.size();i++)
    {
        int cur = 10 - i;
        if(cnt[cur] != 0)
        {
            cout << cur;
            cnt[cur]--;
        }
        else
        {
            int j = cur;
            while(cnt[j] == 0)
            {
                j++;
            }
            cout << j;
            cnt[j]--;
        }
    }
    cout << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}